#include <REGX52.H>
#include "LCD1602.h"
#include "Delay.h"
#include "MatrixKey.h"


unsigned char KeyNum;
unsigned int Password,Count = 0;

void main()
{
	LCD_Init();
	LCD_ShowString(1,1,"Password:");
	while(1)
	{
		KeyNum=MatrixKey();
		if(KeyNum)
		{
			if(KeyNum<=10)    //按下s1-s10的按键,输入密码
			{
				if(Count < 4)   //4位密码
				{
					Password*=10;   //密码左移
					Password+=KeyNum%10;  //获取一位密码
					Count++;   //计数
				}
				LCD_ShowNum(2,1,Password,4);
			}
			if(KeyNum==11) //s11为确认键
			{
				if(Password==2456)  //真确密码
				{
					LCD_ShowString(1,14,"OK ");  //密码真确，显示Ok
				}
				else
				{
					LCD_ShowString(1,14,"ERR");  //错误，显示err
				}
				 
				//清零
				Password=0;
				Count=0;
				LCD_ShowNum(2,1,Password,4);
			}
			if(KeyNum==12) //按下s12取消,全部清除
			{
				Password=0;
				Count=0;
				LCD_ShowNum(2,1,Password,4);
				LCD_ShowString(2,6,"         ");
			}
			if(KeyNum==13)
			{
				LCD_ShowString(2,6,"520");
			}
			if(KeyNum==14)
			{
				LCD_ShowString(2,9,"1314   ");
			}
			if(KeyNum==15)
			{
				LCD_ShowString(2,6,"HaHaHa   ");
			}
			if(KeyNum==16)
			{
				LCD_ShowString(2,6,"Hello HJX");
			}
		}
	}
}